package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.CornerPathEffect
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* ReturnShareView
* */
class ReturnShareView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            strokeCap = Paint.Cap.ROUND
            style = Paint.Style.STROKE
            strokeJoin = Paint.Join.ROUND
            color = context.resources.getColor(R.color.color_079F29)
        }
    }

    private val mPath by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            save()
            translate(cx + cx / 12, cy + cy / 10)

            mPaint0.strokeWidth = (cx / 18).coerceAtLeast(minStrokeWidth)
            mPath.apply {
                reset()

                moveTo(cx * 2 / 3, -cy / 5 - cy / 10)
                lineTo(cx / 4, cy * 1 / 5)
                lineTo(cx / 4, -cy / 5)
                quadTo(
                    -cx * 3 / 4 + cx / 4,
                    -cy / 3 + cy / 4,
                    -cx * 3 / 4,
                    cy * 3 / 5
                )

                quadTo(
                    -cx * 3 / 4,
                    -cy / 3,
                    cx / 4,
                    -cy * 2 / 5
                )

                lineTo(cx / 4, -cy * 4 / 5)

                close()
            }
            drawPath(mPath, mPaint0)

            restore()
        }
    }
}